package gameObject
{
	import flash.events.Event;
	import flash.net.Responder;
	
	import gameObject.resources3D.EnemyResource;

	public class Enemy extends GameObjectBase
	{
		public var pid:uint;				//在实例化时赋予怪物编号
		
		private var _id:uint;				//哪一类怪
		private var _name:String;		//显示名称
		private var _radius:Number;		//碰撞半径
		private var _mspd:Number;		//移动速度
		private var _mran:Number;		//巡逻范围半径
		private var _eran:Number;		//警戒范围半径
		private var _aran:Number;		//攻击范围半径
		private var _pow:int;			//攻击力
		private var _actrate:Number;		//攻击频率
		private var _maxHp:uint;			//hp
		private var _def:uint;			//防御力
		
		public function get radius():Number
		{
			return _radius;
		}

		public function get mspd():Number
		{
			return _mspd;
		}
		
		public function get mran():Number
		{
			return _mran;
		}
		
		//////////////////////////////////////
		public function Enemy(id:uint)
		{
			_id = id;
			if(Global.enemyValues[_id] == undefined)
			{
				Global.phpServer.call("gameServer.getEnemyValues", new Responder(gotValues),_id);
			}else setValues();
		}

		private function gotValues(obj:Object):void
		{
			var enemyValues:Object = new Object;
			enemyValues.name = obj.name;
			enemyValues.radius = obj.radius;
			enemyValues.mspd = obj.mspd;
			enemyValues.mran = obj.mran;
			enemyValues.eran = obj.eran;
			enemyValues.aran = obj.aran;
			enemyValues.pow = obj.pow;
			enemyValues.actrate = obj.actrate;
			enemyValues.hp = obj.hp;
			enemyValues.def = obj.def;
			
			Global.enemyValues[_id] = enemyValues;
			
			setValues();
		}
		
		private function setValues():void
		{
			var enemyValues:Object = Global.enemyValues[_id];
			
			_name = enemyValues.name;
			_radius = enemyValues.radius;
			_mspd = enemyValues.mspd;
			_mran = enemyValues.mran;
			_eran = enemyValues.eran;
			_aran = enemyValues.aran;
			_pow = enemyValues.pow;
			_actrate = enemyValues.actrate;
			_maxHp = enemyValues.hp;
			_def = enemyValues.def;
			
			_resource = new EnemyResource(_id);
			
			_resource.addEventListener(Event.COMPLETE,loadedResource);
			_resource.load();
		}
		
		private function loadedResource(e:Event):void
		{
			
			_resource.removeEventListener(Event.COMPLETE,loadedResource);
			
			addChild(_resource);
			dispatchEvent(new Event(Event.COMPLETE));
		}
	}
}